﻿CREATE PROCEDURE [ServiceEngine].[DeleteAssertionType]
@ID UNIQUEIDENTIFIER
AS
BEGIN
	DECLARE @ErrorMessage NVARCHAR(4000);
	DECLARE @ErrorSeverity INT;
	DECLARE @ErrorState INT;
	SET NOCOUNT ON;

	BEGIN TRY
		BEGIN TRANSACTION

		DELETE	ServiceEngine.AssertionTypes_Subjects
		WHERE	AssertionTypeID = @ID

		DELETE	ServiceEngine.AssertionTypes 
		WHERE	AssertionTypeID = @ID

		DELETE	ServiceEngine.Names
		WHERE	EntityID = @ID and EntityTypeID = 18

		COMMIT TRANSACTION
	END TRY
	BEGIN CATCH
		SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();

		IF XACT_STATE() <> 0 ROLLBACK TRANSACTION;

		RAISERROR (@ErrorMessage, 
				   @ErrorSeverity,
				   1);
	END CATCH
END

